<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>

<table id="dataTable"></table>
<script type="text/html" id="goodsTpl">
    <div style="line-height:18px;">
    <div><p>满{{d.money_begin}}元减{{d.money_del}}元</p></div>
</script>

<script type="text/html" id="userTpl">
    <div style="line-height:18px;">
    <div><p>{{d.user_type==0?'所有用户':(d.user_type==1?'内部员工':'销售人员')}}</p></div>
</script>

<script type="text/html" id="timesTpl">
    <div style="line-height:18px;">
    <div><p>{{d.use_bg_time}}~{{d.use_end_time}}</p></div>
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('edit')}?type=index&id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1000px', height: '500px', title: '修改优惠券'}">修改</a><a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>
{include file="system@block/layui" /}
<script id="toolbar" type="text/html">
    <a href="{:url('add')}?type=index" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '1000px', height: '500px', title: '添加优惠券'}">&nbsp;添加</a>
    <!-- <a href="{:url('index_export')}" class="layui-btn layui-btn-primary layui-icon layui-icon-play" width="460" height="270">&nbsp;导出</a>
    <button type="button" class="layui-btn" id="test1">
        <i class="layui-icon">&#xe67c;</i>导入excel
      </button> -->
</script>
<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {field: 'id', title: 'ID'}
                ,{field: 'quan_name', title: '名称'}
                ,{field: 'quan_desc', title: '描述'}
                ,{ title: '优惠券内容',templet:'#goodsTpl'}
                ,{ title: '是否对外发放',templet:'#status'}
                ,{ title: '发放对象',templet:'#userTpl'}
                ,{field: 'get_num', title: '已领取'}
                ,{field: 'use_num', title: '已使用'}
                ,{field: 'rest_num', title: '剩余'}
                ,{ title: '有效期',templet:'#timesTpl'}
                ,{title: '操作', width: 120, templet: '#buttonTpl'}
            ]]
            ,done: function(){
                if (typeof(layui.global.addTableTool) !== 'undefined') {
                    layui.global.addTableTool();
                }
            }
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload; //得到 upload 对象
        //创建一个上传组件
        upload.render({
        elem: '#test1'
        ,url: '{:url("goods_import")}'
        ,method:'post'
        ,done: function(res){ //上传后的回调
            // console.log(res);
            if(res.status=='success'){
                layer.msg('导入成功');
                window.location.reload();
            }
            else{
                layer.msg(res.msg);
            }
        } 
        ,accept: 'file' //允许上传的文件类型
        //,size: 50 //最大允许上传的文件大小
        //,……
        })
    });
</script>